﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace PJ.Presentation.Inventory
{
    /// <summary>
    /// Logique d'interaction pour GetInventoryItemView.xaml
    /// </summary>
    public partial class GetInventoryItemView : UserControl, IGetInventoryItemView
    {
        public GetInventoryItemView()
        {
            InitializeComponent();
        }
        public void SetGetInventoryItemCommand(ICommand command)
        {
            this.DataContext = command;
        }

        void ExecuteGetInventoryItemCommand()
        {
            if (InventoryItemID != "")
            {
                ICommand command = this.DataContext as ICommand;
                if (command != null)
                {
                    command.Execute(InventoryItemID);
                    InventoryItemID = "";
                }
            }
        }

        private void InventoryID_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                ExecuteGetInventoryItemCommand();
            }
        }

        private string InventoryItemID
        {
            get
            {
                return tbInventoryItemID.Text;
            }
            set
            {
                tbInventoryItemID.Text = "";
            }
        }

        private void btOK_Click(object sender, RoutedEventArgs e)
        {
            ExecuteGetInventoryItemCommand();
        }
    }
}

